home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Tools / nShell™ 1.0.3 / nShell / User's Guide / 11 Drag and Drop < prev    next >
Encoding:
Text File  |  1994-09-28  |  5.1 KB  |  143 lines  |  [TEXT/ttxt]

  1. 11 Drag and Drop
  2. ================
  3.  
  4. Two methods of drag and drop access have been added to the nShell.  The first, using text files, allows the user to quickly start and run scripts within the nShell application.  The second method, using a separate engine, allows scripts to be converted to stand alone drag and drop applications.  This second method allows files, folders and disks to be dropped on scripts and accessed as standard script parameters.
  5.  
  6. Either kind of script may also be run by typing its name on the command line.  The script would then be run in the existing window.
  7.  
  8. System Variables
  9. ----------------
  10.  
  11. On startup, both kinds of scripts search out the nShell application and set their paths based upon that directory.  These paths may be modified by the script.  The initial values are:
  12.  
  13. PWD = "script directory"
  14. HOME = "nShell application directory"
  15. PATH = ":/nShell application directory:bin"
  16. TMP = "nShell application directory:tmp"
  17.  
  18. TEXT scripts
  19. ------------
  20.  
  21. You may write TEXT scripts using your any text editor, including the TeachText or SimpleText editor that came with your Macintosh.  The easiest way to run a TEXT script is to drop it on the nShell application.  A new shell window will be opened, and the script will be run.  When the script completes, a prompt is provided to the user.
  22.  
  23. To make the script clickable, change the file's creator to 'NSHA':
  24.  
  25. chattr my_script -c NSHA
  26.  
  27. The Droplet Engine
  28. ------------------
  29.  
  30. The advantage of using a drag and drop engine, is that it allows files, folders and disks to be dropped on scripts and accessed as standard script parameters.
  31.  
  32. Droplets terminate automatically when their scripts complete.
  33.  
  34. Writing a Droplet
  35. -----------------
  36.  
  37. Make a copy of the "nShell™ droplet" engine.  You can use the finder "Duplicate" function, or the nShell "cp" command.  Give this copy of the drag and drop template a unique name.
  38.  
  39. Method 1 - Direct Editing
  40. - - - - - - - - - - - - -
  41.  
  42. Drag your new icon onto a BBEdit icon, and type in your script.  Close the file and you're done.
  43.  
  44. NOTE:  If you use "Save As" within BBEdit, a new text file will be created, and the executable portion of the droplet will not be copied.  
  45.  
  46. Method 2 - Appending a file
  47. - - - - - - - - - - - - - -
  48.  
  49. If you have an existing script file which you would like to make into a drag and drop application, you can 'cat' the file onto a copy of the "nShell™ droplet":
  50.  
  51. cat my_script >> template_copy
  52.  
  53. and you're done.
  54.  
  55. NOTE:  Never use the ">" operator, as this will delete and replace the target with a new TEXT file.
  56.  
  57. Parameters
  58. ----------
  59.  
  60. The normal script parameters $#, $0...$n will be set up with any items dropped onto the application.  Specifically:
  61.  
  62. $# = The number of parameters (1 = script only, 2 = script + 1 param, etc.)
  63. $0 = The name of the script (not a full pathname)
  64. $1 = The full pathname of the first dropped item
  65. $2 = The full pathname of the second dropped item
  66. ...
  67.  
  68. The parameters may be files, folders, or disks but are always represented as pathnames.  Remember to use quotes around these variables, as in
  69.  
  70. chattr "$1" -c 'NSHA'
  71.  
  72. In nShell-Pro, a while-shift loop may be used to process a large number of dropped files:
  73.  
  74. #
  75. # Set all text files to Creator = 'NSHA'
  76. #
  77. echo "working..."
  78. while shift do
  79.     ls "$0" -l | read crea type extra
  80.     if .eq. $type TEXT then echo ' ' ; chattr "$0" -c NSHA endif
  81. done
  82.  
  83. Limitations:  The total length of all dropped pathnames may not exceed 10k characters.  Beyond this input is ignored.  Only those files dropped on the application as it is opened are set as parameters.  Anything dropped on the script after it is running is ignored (the finder is given an errAEEventNotHandled).
  84.  
  85. Memory
  86. ------
  87.  
  88. The default memory size for droplets is 250k. That should be enough for quite a lot of processing.  If you think you are going to need it, bump the memory.  The nShell and the droplet engine start complaining about low memory when 80k is left.
  89.  
  90. Hint #1
  91. -------
  92.  
  93. If you're not sure what's going on with a drag an drop script, add
  94.  
  95. env
  96. echo ' '
  97. echo 'Press <Return> to continue...'
  98. echo ' '
  99. read foo
  100.  
  101. as the first lines.  That'll tell you what your dropped files ended up looking like. 
  102.  
  103. And if you don't want to fall off the end of the script right away, use 'delay 5' or 'read foo' or something as the last line.
  104.  
  105. Hint #2
  106. -------
  107.  
  108. To run a TEXT script in a new window, you could double-click it in the Finder or type:
  109.  
  110. odoc my_script
  111.  
  112. To run a droplet as a stand-alone application,  you could double-click it in the Finder or launch it:
  113.  
  114. launch my_droplet
  115.  
  116. Or use "odoc" to send it a parameter:
  117.  
  118. odoc my_parameter my_droplet
  119.  
  120. Hint #3
  121. -------
  122.  
  123. Any script can run any other script.  So create a drag and drop application containing the line
  124.  
  125. "$1"
  126.  
  127. and you have a program that will run any nShell script dropped on it and then terminate.
  128.  
  129. In nShell-Pro, a while-shift loop could be used to execute all dropped scripts:
  130.  
  131. while shift do
  132.     ls "$0" -l | read crea type extra
  133.     if .eq. $crea NSHA then
  134.         if .eq. $type TEXT then
  135.             "$0"
  136.         endif
  137.     endif
  138. done
  139.  
  140. System 6
  141. --------
  142.  
  143. Under System 6, the TEXT method should be used to create clickable scripts.  The "nShell™ droplet" application will run within the nShell folder, but offers no advantages over the TEXT method.